﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class print_bug : CommonPage
    {
        protected DataRow dr;
        protected bool images_inline;
        protected bool history_inline;

        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);

            security = new Security();
            security.check_security(HttpContext.Current, Security.ANY_USER_OK);

            string string_bugid = Request.QueryString["id"];

            int bugid = Convert.ToInt32(string_bugid);

            dr = btnet.Bug.get_bug_datarow(bugid, security);

            if (dr == null)
            {
                Response.Write("<link rel=StyleSheet href=btnet.css type=text/css>");
                security.write_menu(Response, PluralBugLabel);
                Response.Write("<p>&nbsp;</p><div class=align>");
                Response.Write("<div class=err>");
                Response.Write(Bug_Util.capitalize_first_letter(SingularBugLabel));
                Response.Write(" not found:&nbsp;" + string_bugid + "</div>");
                Response.Write("<p><a href=bugs.aspx>View ");
                Response.Write(PluralBugLabel);
                Response.Write("</a>");
                Response.End();
            }



            titl.Text = Bug_Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                + Bug_Util.capitalize_first_letter(SingularBugLabel)
                + " ID" + string_bugid + " " + (string)dr["short_desc"];


            // don't allow user to view a bug he is not allowed to view
            if ((int)dr["pu_permission_level"] == 0)
            {
                Response.Write("<link rel=StyleSheet href=btnet.css type=text/css>");
                security.write_menu(Response, PluralBugLabel);
                Response.Write("<p>&nbsp;</p><div class=align>");
                Response.Write("<div class=err>You are not allowed to view this bug</div>");
                Response.Write("<p><a href=bugs.aspx>View Bugs</a>");
                Response.End();
            }

            HttpCookie cookie = Request.Cookies["images_inline"];
            if (cookie == null || cookie.Value == "0")
            {
                images_inline = false;
            }
            else
            {
                images_inline = true;
            }

            cookie = Request.Cookies["history_inline"];
            if (cookie == null || cookie.Value == "0")
            {
                history_inline = false;
            }
            else
            {
                history_inline = true;
            }
    
        }
    }
}
